<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script type="text/javascript">
      // 展开一个数组
      let arr1 = [1, 3, 5, 7, 9];
      let arr2 = [2, 4, 6, 8, 10];
      console.log(...arr1);

      //连接数组
      let arr3 = [...arr1, ...arr2];
      console.log(arr3);

      //   在函数中使用
      function sum(...numbers) {
        return numbers.reduce((per, curr) => {
          return per + curr;
        });
      }
      console.log(sum(1, 2, 3, 4));

      //对象复制
      let person = { name: 'tom', age: 18 };
      let person2 = { ...person };
      //   console.log(...person); //保存，展开运算符不能展开对象
      person.name = 'jerry';
      console.log(person);
      console.log(person2);

      //   合并
      let person3 = { ...person, name: 'jack', address: '北京' };
      console.log(person3);
    </script>
  </body>
</html>
